package com.gr.dmbackend.service.Impl.dormaddmin;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gr.dmbackend.mapper.DormaddminMapper;
import com.gr.dmbackend.model.Dormaddmin;
import com.gr.dmbackend.service.dormaddmin.GetDormAdminInfoService;
import com.gr.dmbackend.utils.GetUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GetDormAdminInfoServiceImpl implements GetDormAdminInfoService {

    @Autowired
    private DormaddminMapper dormaddminMapper;

    @Override
    public JSONObject getDormAdminInfo() {

        JSONObject resp = new JSONObject();

        int userId = GetUserUtil.getCurrentUser().getId();
        QueryWrapper<Dormaddmin> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        Dormaddmin dormaddmin = dormaddminMapper.selectOne(queryWrapper);
        if (dormaddmin == null) {
            resp.put("error_message", "当前用户不存在");
            return resp;
        }
        resp.put("name", dormaddmin.getName());
        resp.put("error_message", "success");

        return resp;
    }
}
